﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="list.aspx.vb" Inherits="quizzes.list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2 class="pageTitle">List of quizzes</h2>
    <h3 class="pageTitle">クイズのリスト</h3>

    Sort by&hellip;
    <asp:DropDownList ID="ddl_sortBy" runat="server" AutoPostBack="true">
        <asp:ListItem runat="server" value="Timestamp" Selected="True">what's new? (新しい順に並べます。)</asp:ListItem>
        <asp:ListItem runat="server" Value="Title">what is it called? (タイトル順に並べます。)</asp:ListItem>
        <asp:ListItem runat="server" Value="Creator">who made it? (作った人順に並べます。)</asp:ListItem>
        <asp:ListItem runat="server" Value="QuestionCount">how many questions are there? (質問の数の順に並べます。)</asp:ListItem>
    </asp:DropDownList>

    <asp:ListView ID="listview_quizzes" runat="server" DataSourceID="datasource_quizzes">
        <EmptyDataTemplate>
            <p class="error">
                I can't find any quizzes.
            </p>
        </EmptyDataTemplate>

        <LayoutTemplate>
            <div ID="itemPlaceholder" runat="server"></div>
            <div>
                <asp:DataPager ID="DataPager1" runat="server">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                            ShowNextPageButton="False" ShowPreviousPageButton="False" />
                        <asp:NumericPagerField />
                        <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
                            ShowNextPageButton="False" ShowPreviousPageButton="False" />
                    </Fields>
                </asp:DataPager>
            </div>
        </LayoutTemplate>

        <ItemTemplate>
            <div>
                <div style="float:right;">
                    <neonLearn:UserFlash runat="server" Size="Small" UserName='<%# Eval("Creator") %>' ID="UserFlash" />
                </div>
                
                <h3 class="quizTitle">
                    <asp:HyperLink runat="server"
                                    NavigateUrl='<%# "../details.aspx?GUID=" & Container.DataItem("GUID")%>'>
                                    <%# Container.DataItem("Title")%>
                    </asp:HyperLink>
                </h3>
                <strong><%# Container.DataItem("QuestionCount")%></strong> questions
                <p runat="server" Visible='<%# Not IsDbNull(Container.DataItem("Description")) %>'>
                    <%# Container.DataItem("Description")%>
                </p>
            </div>
            <hr style="clear:both"/>
        </ItemTemplate>
    </asp:ListView>

    <asp:SqlDataSource ID="datasource_quizzes" runat="server" 
        ConnectionString="<%$ ConnectionStrings:quizzes_db_ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:quizzes_db_ConnectionString.ProviderName %>" 
        
        
        SelectCommand="SELECT quizzes.Title, quizzes.Creator, quizzes.Description, quizzes.[GUID], quizzes.[Timestamp], profiles.Picture, COUNT(questions.QuizGUID) AS QuestionCount FROM ((quizzes INNER JOIN profiles ON quizzes.Creator = profiles.UserName) INNER JOIN questions ON quizzes.[GUID] = questions.QuizGUID) GROUP BY quizzes.Title, quizzes.Creator, quizzes.Description, quizzes.[GUID], quizzes.[Timestamp], profiles.Picture ORDER BY quizzes.[Timestamp] DESC">
    </asp:SqlDataSource>
</asp:Content>
